package com.bnz.vo;

import com.bnz.enumcode.ResultCode;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
public class Message {
    private Boolean success;
    private Integer code;
    private String message;
    private Map<String, Object> data = new HashMap<String, Object>();

    public Message(Boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public static Message ok() {
        return new Message(true, ResultCode.SUCCESS.code, "成功");
    }

    public static Message error() {
        return new Message(false, ResultCode.ERROR.code, "失败");
    }

    public Message success(Boolean success) {
        this.success = success;
        return this;
    }

    public Message message(String message) {
        this.message = message;
        return this;
    }

    public Message code(Integer code) {
        this.code = code;
        return this;
    }

    public Message data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public Message data(Map<String, Object> map) {
        this.data = map;
        return this;
    }
}
